

#include "Core/Signpost.h"

#include "Components/BoxComponent.h"
#include "Core/EnemyZDCharacter.h"

ASignpost::ASignpost()
{
	PrimaryActorTick.bCanEverTick = true;

	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent"));
	SetRootComponent(BoxComponent);
}

void ASignpost::BeginPlay()
{
	Super::BeginPlay();

	BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &ASignpost::OnComponentOverlap);
}

void ASignpost::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void ASignpost::OnComponentOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (!NextPoint) return;
	

	// UE_LOG(LogTemp, Warning, TEXT("到达检查点，下一点：%s"), *NextPoint->GetActorLocation().ToString());
	if (AEnemyZDCharacter* Enemy = Cast<AEnemyZDCharacter>(OtherActor))
	{
		Enemy->SetNextLocation(NextPoint->GetActorLocation());
	}
}

